<div class="sc-cnt-publicacao">
        
    <div class="col itg-mn-disciplina">
        <h2>Publicar Tópicos<?php //echo $this->dis['DCP_NOM']; ?></h2>
        <ul>
        <?php foreach($this->menu as $row){ ?> 
            <li><a href="<?php echo $this->baseUrl($this->modulo.'/'.$this->controller.'/index/dcp_id/'.$row['DCP_ID']); ?>"><?php echo $row['DCP_NOM']; ?></a></li>
        <?php } ?>
        <ul> 
    </div> 
    
    <div class="content-tb">
        <div class="tl-pag">Tópicos Publicados <a class="btn_nv" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => '')); ?>">Publicar Tópico</a></div>
        
        <table class="nrmprd">          
        <?php foreach($this->result as $key => $row){ 
            $query = 'SELECT SQL_CACHE TPC_NOM FROM TOPICO WHERE TPC_id in('.$row['TPC_ID'].')';
            $result = $this->db->fetchAll($query);
            $topicos = '';
            foreach($result as $r){
                $topicos .= $r['TPC_NOM'].', '; 
            }
            $topicos = substr($topicos, 0,-2);
            
            $cursos = '';
            if(strlen($row['ALU_ID']) > 0){
                $query = 'SELECT SQL_CACHE ALU_NOM FROM ALUNO WHERE ALU_ID in('.$row['ALU_ID'].') AND ALU_STA = 1 ORDER BY ALU_NOM';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['ALU_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            } else if(strlen($row['CUR_ID']) > 0){
                $query = 'SELECT SQL_CACHE n.NRT_NOM '
                        .' FROM CURSO c, CURSOBASE cb, NUMEROTURMA n '
                        .' WHERE c.CBS_ID = cb.CBS_ID AND c.CUR_TRM = n.NRT_ID AND c.CUR_ID in('.$row['CUR_ID'].') '
                        .' ORDER BY n.NRT_SEM ASC, n.NRT_NOM ASC, c.CUR_ID ASC';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['NRT_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            } else if(strlen($row['CBS_ID']) > 0){
                $query = 'SELECT SQL_CACHE CBS_NOM FROM CURSOBASE  WHERE CBS_ID in('.$row['CBS_ID'].') ORDER BY CBS_ORD ASC';
                $result = $this->db->fetchAll($query);
                foreach($result as $r){
                    $cursos .= $r['CBS_NOM'].', '; 
                }
                $cursos = substr($cursos, 0,-2); 
            }           
        ?>
            <tr>
                <td rowspan="2"><?php echo Datetools::invertDH_D($row['PBC_DATHOR']); ?></td>
                <td class="w100"><?php echo $topicos; ?></td>
                <td class="bc"><a class="btn" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['PBC_ID'])); ?>">editar</a></td>
                <td class="bc"><a class="btn" href="javascript:void(0);" onclick="list_delete_msg('<?php echo $this->controller; ?>',<?php echo $row['PBC_ID'] ?>,$(this),'Material <?php echo Datetools::invertDH($row['PBC_DATHOR']);?>');">excluir</a></td>
            </tr>
            <tr>
                <td class="w100" colspan="3"><?php echo $cursos; ?></td>
            </tr>
        <?php } ?>
        </table>
    </div>
    
</div>

<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
 
